package system

import (
	"github.com/beego/beego/v2/client/orm"
	"time"
)

type SysXcxBanner struct {
	SysXcxBannerId uint64    `orm:"column(sys_xcx_banner_id);pk"`
	BannerUrl      string    `description:"banner地址"`
	JumpUrl        string    `description:"跳转地址"`
	Position       string    `description:"位置"`
	CreateTime     time.Time `description:"创建时间"`
	ModifyTime     time.Time `description:"修改时间"`
}

type SysXcxBannerView struct {
	SysXcxBannerId uint64 `orm:"column(sys_xcx_banner_id);pk"`
	BannerUrl      string `description:"banner地址"`
	JumpUrl        string `description:"跳转地址"`
	Position       string `description:"位置"`
	CreateTime     string `description:"创建时间"`
	ModifyTime     string `description:"修改时间"`
}

type SysXcxBannerReq struct {
	BannerUrl string `description:"banner地址"`
	JumpUrl   string `description:"跳转地址"`
	Position  string `description:"位置"`
}

// Add 新增
func (a *SysXcxBanner) Add() (lastId int64, err error) {
	o := orm.NewOrm()
	lastId, err = o.Insert(a)
	return
}

type SysXcxBannerDelReq struct {
	SysXcxBannerId uint64 `description:"banner id"`
}

// Add 新增
func (a *SysXcxBanner) Delete() (err error) {
	o := orm.NewOrm()
	sql := ` DELETE FROM sys_xcx_banner WHERE sys_xcx_banner_id = ? `
	_, err = o.Raw(sql, a.SysXcxBannerId).Exec()
	return
}

func (r *SysXcxBanner) GetSysXcxBannerList() (items []*SysXcxBannerView, err error) {
	o := orm.NewOrm()
	sql := `SELECT * FROM sys_xcx_banner `
	sql += ` ORDER BY create_time DESC `
	_, err = o.Raw(sql).QueryRows(&items)
	return
}
